import logging
import os
from datetime import datetime
from utils.data_helper import get_path

def get_logger():
    # 获取当前文件所在目录
    log_dir=get_path('reports/logs')
    # 确保日志目录存在
    os.makedirs(log_dir, exist_ok=True)
    # 生成带时间戳的日志文件名
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    log_file = os.path.join(log_dir, f"test_{timestamp}.log")
    # 配置日志
    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s %(name)s %(levelname)s %(message)s',
        handlers=[
            logging.FileHandler(log_file, encoding='utf-8'),
            logging.StreamHandler()
        ],
        force=True  # 强制重新配置
    )

    return logging.getLogger(__name__)


